﻿using System.Globalization;
using System.Windows;
using Avalonia.Data.Converters;

namespace KinonekoSoftware.Studio.Resources.Converters
{
    public class FindGeometryByNameConverter : IMultiValueConverter
    {
        public object[] ConvertBack(object value,  Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
        
        public object Convert(IList<object> values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values is null || values.Count <1)
            {
                return null;
            }

            var fe   = values[0] as Control;
            var name = values[1]?.ToString();

            if (string.IsNullOrEmpty(name))
            {
                return null;
            }

            var i = fe?.FindResource(name);
            return i;
        }
    }
}